import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;

import javax.swing.ImageIcon;

import edu.jhu.tcj.purfuit.Game;
import edu.jhu.tcj.purfuit.Player;


public class EndGamePanel extends GamePanel {
	
	private Game thisGame = null;
	private Application application = null;
	private Image img;
	private Image firework;
	
	public EndGamePanel(Application application){
		this.application = application;
		ImageIcon imageIcon = new ImageIcon(getClass().getResource("images/smiley.png"));
		img = imageIcon.getImage();
		firework = new ImageIcon(getClass().getResource("images/fireworks.gif")).getImage();
	}
	
	@Override
	public void mouseClicked(MouseEvent e) {
		application.showSelectionPanel();
	}
	
	@Override
	public void keyPressed(KeyEvent ke) {
		application.showSelectionPanel();
	}
	
	protected void paintComponent(Graphics g) {
		super.paintComponent(g);
		Player winner = thisGame.getWinner();
		g.setColor(Color.yellow);
		g.fillRoundRect(0, 0, 800, 550, 80, 80);
		g.setColor(Color.black);
		g.setFont(new Font("Tahoma", Font.BOLD, 32));
		g.drawString("CONGRATULATIONS " + winner.getName() + " YOU HAVE WON!", 20, 212);
		g.drawImage(img, getWidth()/2-img.getWidth(null)-img.getWidth(null)/2, getHeight()-img.getHeight(null)-50, null);
		g.drawImage(img, getWidth()/2+img.getWidth(null)/2, getHeight()-img.getHeight(null)-50, null);
		g.drawImage(firework, getWidth()/2 - firework.getWidth(this)/2, getHeight()/2- firework.getHeight(this), this);
	}
	
	public void setGame(Game game) {
		thisGame = game;
	}
}
